package com.laosg.study.base.ch6

/**
  * Created by kaimin on 10/5/2019.
  * time : 09:07
  */
object TemplateDemo {

  def main(args: Array[String]): Unit = {

    for(item<-Array(Dolla(123),Currency(500,"RMB"),NoAmout)){
        var res = item match {
          case Dolla(v)=>{
            "$"+v
          }
          case Currency(v,u)=>v+u
          case NoAmout=>"//"
        }
      println("结果是："+res)
    }

    val sal=Bundle("书籍",10,Book("漫画",10),Bundle("文学",10,Book("水浒",1),Book("维持",20)))


    var res  = sal match {
      case Bundle(_,_,Book(des,_),_*)=>des
    }
    println("漫画结果；"+res)

    val bd = sal match {
      case Bundle(_,_,art @ Book(_,_),rest @ _*)=>(art,rest)
    }
    println("绑定的结果:"+bd)


  }
  abstract class Amount

  case class Dolla(value:Double) extends Amount
  case class Currency(value:Double,unit:String) extends Amount
  case class NoAmout() extends Amount


  abstract class Item
  case class Book(des:String,price:Double) extends Item

  case class Food(des:String,price:Double) extends Item

  case class Bundle(des:String,price:Double,item: Item*) extends Item


}
